<?php
	/*
	* @package ToboAds Module
	* @copyright Copyright (C) 2007 Joomlaspan.com. All rights reserved.
	* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
	* Joomla! is free software.
	* This extension is made for Joomla version 1.0.x;
	* Also works for Joomla 1.5 in legacy mode;
	*/

	/**
	This file is part of ToboAds plugins.
	
	ToboAds plugins is free software; you can redistribute it and/or modify
	it under the terms of the GNU Lesser General Public License as published by
	the Free Software Foundation; either version 2.1 of the License, or
	(at your option) any later version.
	
	ToboAds plugins is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU Lesser General Public License for more details.
	
	You should have received a copy of the GNU Lesser General Public License
	along with WideImage; if not, write to the Free Software
	Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
	**/



	// direct access to this file if not allowed
	defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );



	// publisher ID
	$publisher_id = $params->get('toboads_publisher_id');
	$publisher_id = preg_match("/^[a-f0-9]{32}$/i", $publisher_id) > 0 ? $publisher_id : "";

	// ad format
	$ad_format = $params->get('toboads_ad_format');
	if (!in_array($ad_format, array('180x150','234x60','300x250','336x280','468x60','728x90','120x600','120x240','160x240','125x125','160x600','250x250')))
		$ad_format = '120x240';

	// open_new_window
	$open_new_window = $params->get('toboads_open_new_window') ? 'true' : 'false';

	// ad types
	$ad_type_text = $params->get('toboads_ad_type_text') ? 'true' : 'false';
	$ad_type_shop = $params->get('toboads_ad_type_shop') ? 'true' : 'false';
	$ad_type_rich = $params->get('toboads_ad_type_rich') ? 'true' : 'false';

	// colors
	if (!function_exists('toboads_is_valid_color'))
	{
		function toboads_is_valid_color($color)
		{
			if (preg_match("/^#[0-9a-f]{6}$/i", $color) > 0) // RGB code
				return true;
			return false;
		}
	}
	// border color
	$color_border = $params->get('toboads_color_border');
	$color_border = toboads_is_valid_color($color_border) === true ? $color_border : "";
	// background color
	$color_bg     = $params->get('toboads_color_bg');
	$color_bg     = toboads_is_valid_color($color_bg)     === true ? $color_bg     : "";
	// title color
	$color_title  = $params->get('toboads_color_title');
	$color_title  = toboads_is_valid_color($color_title)  === true ? $color_title  : "";
	// text color
	$color_text   = $params->get('toboads_color_text');
	$color_text   = toboads_is_valid_color($color_text)   === true ? $color_text   : "";
	// link color
	$color_link   = $params->get('toboads_color_link');
	$color_link   = toboads_is_valid_color($color_link)   === true ? $color_link   : "";

	// ad channel
	$channel = $params->get('toboads_channel');
	$channel = (preg_match("/^[0-9a-f]{7}$/", $channel) > 0) ? $channel : "";



	// invocation code
	if ($publisher_id != "")
	{
		echo "
<!-- ToboAds -->
<script language=\"javascript\" type=\"text/javascript\">
<!--
	toboads_publisher_id = \"" . $publisher_id . "\";
	toboads_ad_format = \"" . $ad_format . "\";
	toboads_open_new_window = \"" . $open_new_window . "\";
	toboads_ad_type_text = \"" . $ad_type_text . "\";
	toboads_ad_type_text = \"" . $ad_type_shop . "\";
	toboads_ad_type_text = \"" . $ad_type_rich . "\";
	toboads_color_border = \"" . $color_border . "\";
	toboads_color_bg = \"" . $color_bg . "\";
	toboads_color_title = \"" . $color_title . "\";
	toboads_color_link = \"" . $color_text . "\";
	toboads_color_text = \"" . $color_link . "\";
	toboads_channel = \"" . $channel . "\";
// -->
</script>
";
		echo "<script language=\"javascript\" type=\"text/javascript\" src=\"http://relay-si.toboads.com/\">\r\n";
		echo "</script>\r\n";
		echo "<!-- /ToboAds -->\r\n";
	}

?>